package com.example.demo.service.impl;

import com.example.demo.entity.UserEntity;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    // @Resource
    @Autowired
    private UserMapper userMapper;

    @Override
    public String getUserName() {

        return "数据库查出来的姓名:" + userMapper.getUserName()  + "!!!";

    }

    @Override
    public int addUser(UserEntity user) {
        user.setCreateTime(new Date());
        // todo 其他业务处理
        int id = userMapper.addUser(user);

        return user.getId();
    }

    @Override
    public UserEntity getUserById(int id) {
        return userMapper.getUserById(id);
    }
    @Override
    public int deleteUserById(int id) {
        return userMapper.deleteUserById(id);
    }

    @Override
    public List<UserEntity> list() {
        return userMapper.list();
    }

    @Override
    public int updateUser(UserEntity user) {
        user.setUpdateTime(new Date());
        return userMapper.updateUser(user);
    }
}
